package com.movitech.mobile.cz.base.purchase.controller;


import com.movitech.mobile.cz.base.common.util.CommonConstants;
import com.movitech.mobile.cz.base.common.util.PageCode;
import com.movitech.mobile.cz.base.modules.controller.RestReturnResult;
import com.movitech.mobile.cz.base.purchase.entity.ext.ExtPStrategicPurchaseRequired;
import com.movitech.mobile.cz.base.purchase.entity.ext.PStrategicPurchaseRequiredSaveRequest;
import com.movitech.mobile.cz.base.purchase.entity.ext.StrategicPurchaseRequiredFindRequest;
import com.movitech.mobile.cz.base.purchase.service.PStrategicPurchaseRequiredService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * PStrategicPurchaseRequired 前端控制器
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-03-15
 */
@RestController
@RequestMapping("/v1/pStrategicPurchaseRequired")
@Api(value = "战略采购需求基础操作接口", description = "战略采购需求基础操作接口")
public class PStrategicPurchaseRequiredController {
    @Autowired
    private PStrategicPurchaseRequiredService pStrategicPurchaseRequiredService;

    /*@GetMapping("/allList")
    @ApiOperation(value = "获取所有战略采购需求接口", notes = "获取所有战略采购需求接口")
    public RestReturnResult list() {
        RestReturnResult restResult = RestReturnResult.success();
        Page<PStrategicPurchaseRequired> page = pStrategicPurchaseRequiredService.selectPage(new Page<PStrategicPurchaseRequired>());
        restResult.setData(page);
        return restResult;
    }*/

    /*@PostMapping("/searchList/{pageNumber}")
    @ApiOperation(value = "战略采购需求列表查询接口", notes = "战略采购需求列表查询接口")
    public RestReturnResult searchList(@RequestBody PStrategicPurchaseRequired pStrategicPurchaseRequired,
                                       @ApiParam(value = "分页页数") @PathVariable Integer pageNumber) {
        RestReturnResult restResult = RestReturnResult.success();
        Page<PStrategicPurchaseRequired> page = new Page<>();
        page.setCurrent(pageNumber);
        EntityWrapper wrapper = new EntityWrapper<>();
        wrapper.setEntity(pStrategicPurchaseRequired);
        page = pStrategicPurchaseRequiredService.selectPage(page, wrapper);
        restResult.setData(page);
        return restResult;
    }*/

    @PostMapping("/findStrategicPurchaseRequiredList")
    @ApiOperation(value = "战略采购需求列表查询接口", notes = "战略采购需求列表查询接口")
    public RestReturnResult findStrategicPurchaseRequiredList(@RequestBody StrategicPurchaseRequiredFindRequest strategicPurchaseRequiredFindRequest) {
        RestReturnResult restResult = RestReturnResult.success();
        PageCode page = pStrategicPurchaseRequiredService.findStrategicPurchaseRequiredList(strategicPurchaseRequiredFindRequest);
        restResult.setData(page);
        return restResult;
    }

    @GetMapping("/getPStrategicPurchaseRequired/{id}")
    @ApiOperation(value = "战略采购需求对象ID获取接口", notes = "战略采购需求对对象ID获取接口")
    public RestReturnResult addPStrategicPurchaseRequired(@PathVariable String id) {
        RestReturnResult restResult = RestReturnResult.success();
        ExtPStrategicPurchaseRequired pStrategicPurchaseRequired = pStrategicPurchaseRequiredService.getById(id);
        restResult.setData(pStrategicPurchaseRequired);
        return restResult;
    }

    @PostMapping("/savePStrategicPurchaseRequired")
    @ApiOperation(value = "战略采购需求添加接口", notes = "战略采购需求添加接口:战略采购需求参数:年度,地区公司id,项目id和详情ID列表")
    public RestReturnResult savePStrategicPurchaseRequired(@RequestBody PStrategicPurchaseRequiredSaveRequest strategicPurchaseRequiredSaveRequest) {
        RestReturnResult restResult = RestReturnResult.success();
        pStrategicPurchaseRequiredService.savePStrategicPurchaseRequired(strategicPurchaseRequiredSaveRequest);
        restResult.setData(strategicPurchaseRequiredSaveRequest);
        return restResult;
    }

  /*  @PutMapping("/update")
    @ApiOperation(value = "战略采购需求更新接口", notes = "战略采购需求更新接口")
    public RestReturnResult update(@RequestBody PStrategicPurchaseRequired pStrategicPurchaseRequired) {
        RestReturnResult restResult = RestReturnResult.success();
        pStrategicPurchaseRequiredService.updateById(pStrategicPurchaseRequired);
        restResult.setData(pStrategicPurchaseRequired);
        return restResult;
    }*/

    @GetMapping("/delete/{id}")
    @ApiOperation(value = "战略采购需求通过ID删除接口", notes = "战略采购需求通过ID删除接口")
    public RestReturnResult update(@PathVariable String id) {
        RestReturnResult restResult = RestReturnResult.success();
        boolean flag = pStrategicPurchaseRequiredService.deleteById(id);
        if(!flag){
            restResult.setCode(CommonConstants.FAIL);
        }
        return restResult;
    }

}

